package com.yb.xczx.cloud.auth.service.impl;

import com.yb.core.exception.XczxBusinessException;
import com.yb.core.model.XczxLoginUser;
import com.yb.core.model.XczxResult;
import com.yb.xczx.cloud.auth.generator.XczxCodeGenerator;
import com.yb.xczx.cloud.auth.service.ILoginEntryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Objects;

@Service
@Slf4j
public class LoginEntryServiceImpl implements ILoginEntryService {

     @Autowired
     XczxCodeGenerator xczxCodeGenerator;

     public XczxResult code(XczxLoginUser xczxLoginUser) {

          if(Objects.isNull(xczxLoginUser)|| !StringUtils.hasText(xczxLoginUser.getLoginType())){
               return XczxResult.error(new XczxBusinessException("登陆类型loginType不能为空"));
          }

          String code = xczxCodeGenerator.generate(xczxLoginUser);
          //生成的code
          XczxLoginUser loginUser = new XczxLoginUser();

          loginUser.setCode(code);

          return XczxResult.success(loginUser);
     }
}
